﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Data;

namespace YodaMaster.Models
{
    public class Table
    {
        public DataTable LecturesTable { set; get; }
        public DataTable LecturesTimes {set; get; }
        public DataTable TutorialsTable { set; get; }
        public DataTable TutorialsTimes {set; get; }
        public DataTable LabsTable { set; get; }
        public DataTable LabsTimes {set; get; }
        public DataTable TestsTable { set; get; }
        public DataTable GeneralTable {set; get; }
        public DataTable SubGeneralTable {set; get; }
        public Course course_item { set; get; }

        public Table(Course course)
        {
            course_item = course;
            // Add General information about the course

                GeneralTable = new DataTable();
                GeneralTable.Columns.Add("Faculty", typeof(string));
                GeneralTable.Columns.Add("Course Id", typeof(int));
                GeneralTable.Columns.Add("Course Name", typeof(string));
                GeneralTable.Columns.Add("Course Points", typeof(double));
                GeneralTable.Rows.Add(course.faculty, course.number, course.name, course.points);

           // Add more information
                
                SubGeneralTable = new DataTable();
                SubGeneralTable.Columns.Add("Lecturer in Charge", typeof(string));
                SubGeneralTable.Columns.Add("Lecture Hours", typeof(double));
                SubGeneralTable.Columns.Add("Tutorial Hours", typeof(double));
                SubGeneralTable.Columns.Add("Lab Hours", typeof(double));
                SubGeneralTable.Rows.Add(course.lecturerInCharge, course.lectureHours, course.tutorialHours, course.labHours);
                
            // Add tests table

               TestsTable = new DataTable();
                 TestsTable.Columns.Add("Moed A Start", typeof(DateTime));
                TestsTable.Columns.Add("Moed A End", typeof(DateTime));
                 TestsTable.Columns.Add("Moed B Start", typeof(DateTime));
                 TestsTable.Columns.Add("Moed B End", typeof(DateTime));
                TestsTable.Rows.Add(course.moedA_start, course.moedA_end, course.moedB_start, course.moedB_end);

            // Add Lectures Table
            if (course.lectureHours > 0)
            {
                LecturesTable = new DataTable();
                LecturesTimes = new DataTable();
                LecturesTable.Columns.Add("Group Type", typeof(string));
                LecturesTable.Columns.Add("Group Number", typeof(int));
                LecturesTable.Columns.Add("Lecturer", typeof(string));
                LecturesTimes.Columns.Add("Group Number", typeof(int));
                LecturesTimes.Columns.Add("Location", typeof(string));
                LecturesTimes.Columns.Add("StartTime", typeof(DateTime));
                LecturesTimes.Columns.Add("EndTime", typeof(DateTime));
                foreach (var item in course.lectureList)
                {
                    LecturesTable.Rows.Add(item.groupType.ToString(), item.groupNumber, item.lecturer);
                    LecturesTimes.Rows.Add(item.groupNumber, item.teachingHours.ElementAt(0).location, item.teachingHours.ElementAt(0).startTime, item.teachingHours.ElementAt(0).endTime);
                    if (item.teachingHours.Count == 2)
                    {
                        LecturesTimes.Rows.Add( item.groupNumber, item.teachingHours.ElementAt(1).location, item.teachingHours.ElementAt(1).startTime, item.teachingHours.ElementAt(1).endTime);
                    }
                    if (item.teachingHours.Count == 3)
                    {
                        LecturesTimes.Rows.Add(item.groupNumber, item.teachingHours.ElementAt(2).location, item.teachingHours.ElementAt(2).startTime, item.teachingHours.ElementAt(2).endTime);
                    }
                }
            }

            // Add Tutorial Table
             if (course.tutorialHours > 0)
            {
                TutorialsTable = new DataTable();
                TutorialsTimes = new DataTable();
                TutorialsTable.Columns.Add("Group Type", typeof(string));
                TutorialsTable.Columns.Add("Group Number", typeof(int));
                TutorialsTable.Columns.Add("Lecturer", typeof(string));
                TutorialsTimes.Columns.Add("Group Number", typeof(string));
                TutorialsTimes.Columns.Add("Location", typeof(string));
                TutorialsTimes.Columns.Add("StartTime", typeof(DateTime));
                TutorialsTimes.Columns.Add("EndTime", typeof(DateTime));
                foreach (var item in course.tutorialList)
                {
                    TutorialsTable.Rows.Add(item.groupType.ToString(), item.groupNumber, item.lecturer);
                    TutorialsTimes.Rows.Add(item.groupNumber,item.teachingHours.ElementAt(0).location, item.teachingHours.ElementAt(0).startTime, item.teachingHours.ElementAt(0).endTime);
                    if (item.teachingHours.Count == 2)
                    {
                        TutorialsTimes.Rows.Add(item.groupNumber, item.teachingHours.ElementAt(1).location, item.teachingHours.ElementAt(1).startTime, item.teachingHours.ElementAt(1).endTime);
                    }
                    if (item.teachingHours.Count == 3)
                    {
                        TutorialsTimes.Rows.Add(item.groupNumber,item.teachingHours.ElementAt(2).location, item.teachingHours.ElementAt(2).startTime, item.teachingHours.ElementAt(2).endTime);
                    }
                }
            }

            // Add Labs Table
             if (course.labHours > 0)
            {
                LabsTable = new DataTable();
                LabsTimes = new DataTable();
                LabsTable.Columns.Add("Group Type", typeof(string));
                LabsTable.Columns.Add("Group Number", typeof(int));
                LabsTable.Columns.Add("Lecturer", typeof(string));
                LabsTimes.Columns.Add("Group Number", typeof(int));
                LabsTimes.Columns.Add("Location", typeof(string));
                LabsTimes.Columns.Add("StartTime", typeof(DateTime));
                LabsTimes.Columns.Add("EndTime", typeof(DateTime));
                foreach (var item in course.labList)
                {
                    LabsTable.Rows.Add(item.groupType.ToString(), item.groupNumber, item.lecturer);
                    LabsTimes.Rows.Add(item.groupNumber, item.teachingHours.ElementAt(0).location, item.teachingHours.ElementAt(0).startTime, item.teachingHours.ElementAt(0).endTime);
                    if (item.teachingHours.Count == 2)
                    {
                        LabsTimes.Rows.Add(item.groupNumber,item.teachingHours.ElementAt(1).location, item.teachingHours.ElementAt(1).startTime, item.teachingHours.ElementAt(1).endTime);
                    }
                    if (item.teachingHours.Count == 3)
                    {
                        LabsTimes.Rows.Add(item.groupNumber, item.teachingHours.ElementAt(2).location, item.teachingHours.ElementAt(2).startTime, item.teachingHours.ElementAt(2).endTime);
                    }
                }
            }
              
        }

             
            
        }
    }
